var mygrid;
$(function() {
	mygrid = $("#list").jqGrid({
		url : "netdisk/file/permission/file-permission!datalist",
		datatype : "json",
		postData:pData,
		mtype : 'POST',
		colNames : [ '编', '文件名', '类型', '上传日期','发送人','接受人', '审核人','审核日期','审' ],
		colModel : [
		{
			name:"id",
			index:'id',
			width:20,
			formatter:editFormatter
			
		},{
			name : 'title',
			index : 'title',
			width : 180,
			formatter : downloadFormatter

		}, {
			name : 'fileType',
			index : 'fileType',
			width : 30,
			formatter : imgFormatter
		}, {
			name : 'createTime',
			index : 'createTime',
			width : 130
		// formatter:date
		}, {
			name : 'fromer',
			index : 'fromer',
			width : 60,
			formatter:userFormatter
			
		},{
			name : 'owner',
			index : 'owner',
			width : 60,
			formatter:userFormatter
		},{
			name:"passor",
			index:"passor",
			width:60,
			formatter:userFormatter
		},{
			name:"passedDate",
			index:"passedDate",
			width:130
		},{
			name : 'did',
			index : 'id',
			width : 20,
			formatter : deleteFormater
		}

		],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'createTime',
		sortorder : 'desc',
		viewrecords : true,
		caption : '我的文件',

		width : '750',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	});	
});// end of document ready
function reloadMe(){
	mygrid.trigger("reloadGrid");
}
function selectFormatter(cv, opt, row) {
	var fid = row['id'];
	var title = row['title'];
	var link = $("<input type=\"checkbox\" onclick=\"checkFile('" + fid + "','" + title + "',this.checked);\"></input>");
	return $("<span></span>").append(link).html();

}
function userFormatter(c,opt,row){
	return c==null?'':c.localName;
}
function downloadFormatter(cellvalue, options, rowObject) {
	var eid = rowObject['id'];
	var link = $("<a></a>");
	link.attr("href", "netdisk/file/translate-file!download?fileId="+ eid);
	link.attr("target", "_self");
	link.html("<b>" + cellvalue + "</b>");
	return $("<span></span>").append(link).html();

}
function imgFormatter(cellvalue, options, rowObject) {
	var img = $("<img></img>");
	img.attr("src", sbase+"/images/fileico/"+cellvalue+".jpg");
	img.css("width", "16px");
	img.css("height", "16px");
	return $("<span><span>").append(img).html();
}

function deleteFormater(cv, opt, row) {
	var eid = row['id'];
	var link = $("<a></a>");
	link.attr("href", "javascript:passMe('" + eid + "');");
	link.html("<img src='"+sbase+"images/passed.gif' style='border:none'/>");
	return $("<span></span>").append(link).html();
}

function editFormatter(v,opt,row){
	var ftype  =row['fileType'];
	var eid = row['id'];
	var link = $("<a></a>");
	if(ftype=="doc" 
		|| ftype=="docx"
	    || ftype=="xls"
	    || ftype=="xlsx"
	    || ftype=="ppt"
	    || ftype=="pptx"
	){
		link.attr("href", "netdisk/file/translate-file!openforedit?fileId="+eid);
	}else{
		return '-';
	}
	link.attr("target","_blank");
	link.html("<img src='"+sbase+"/images/file-edit.gif' style='border:none' />");
	return $("<span></span>").append(link).html();
}
function passMe(eid){
	
	$.post("netdisk/file/permission/file-permission!passfile","stringList[0]="+eid,function(){
		reloadMe();
	});
}

function search(){	
	var pms = {"_search":"true"};	
	mygrid.jqGrid('setGridParam',{url:dataurl,postData:pms}).trigger("reloadGrid");
}